#include <UnitTest++.h>
#include "sound.h"

struct stopsound_fixture {
    int was_playing;
    stopsound_fixture() {
        was_playing = playing;
        playing = 0;
        _verge1_stopsound_completed = false;
    }
    ~stopsound_fixture() {
        playing = was_playing;
    }
};

struct sound_is_enabled
    : stopsound_fixture {
    sound_is_enabled() {
        md_device = SOUND_DEVICE_AUTO_DETECT;
    }
};

struct sound_is_playing
    : sound_is_enabled {
    sound_is_playing() {
        playing = 1;
    }
};

struct sound_is_disabled
    : stopsound_fixture {
    sound_is_disabled() {
        md_device = SOUND_DEVICE_NONE;
    }
};

SUITE(stopsound_suite) {

    TEST_FIXTURE(sound_is_playing, stopsound_completes_when_playing) {
        stopsound();
        CHECK(_verge1_stopsound_completed);
    }

    TEST_FIXTURE(sound_is_enabled, stopsound_does_not_complete_when_not_playing) {
        stopsound();
        CHECK(!_verge1_stopsound_completed);
    }

    TEST_FIXTURE(sound_is_disabled, stopsound_does_not_complete_when_sound_device_is_disabled) {
        stopsound();
        CHECK(!_verge1_stopsound_completed);
    }

    TEST_FIXTURE(sound_is_playing, stopsound_saves_last_volume) {
        lastvol = 0;
        mp_volume = 123;
        stopsound();
        CHECK_EQUAL(lastvol, 123);
    }

    TEST_FIXTURE(sound_is_playing, stopsound_zeroes_out_volume) {
        mp_volume = 1;
        stopsound();
        CHECK_EQUAL(mp_volume, 0);
    }
}
